package com.siss.tenancy.elastic;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * 2017/7/3
 * 
 * @author ygw
 * @since 1.0
 */
@Configuration
@EnableSwagger2
//@Profile({"default","dev","lab","cslab","gllab","hhhtlab","lzlab","nnlab","sylab","whlab"}) //表示在开发或测试环境开启，而在生产关闭
public class Swagger2 {
	@Bean
	public Docket createRestApi() {

		 ParameterBuilder tokenParam = new ParameterBuilder();
	        
	        List<Parameter> params = new ArrayList<Parameter>();
	        
	        tokenParam.name("Authorization").description("令牌(Bearer Token) (非必须, 输入框默认值为admin用户token)").modelRef(new ModelRef("string")).parameterType("header").required(false)
	        	.defaultValue("bearer 55a72d44-66fd-4346-bdc3-5ceda9fb6384")
	        	.build();
	      
	        params.add(tokenParam.build()); 

		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.siss.tenancy.elastic")).paths(PathSelectors.any())
				.build().globalOperationParameters(params);

	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("开放接口微服务RESTful APIs").contact("yingw").version("1.0").build();
	}

}
